//
//  PageStatusView.swift
//  edaixi_client_ios
//
//  Created by 刘树华 on 2017/11/10.
//  Copyright © 2017年 刘树华. All rights reserved.
//

import Foundation
import UIKit
let Request_error = 0
let Request_timeout = -999
let DataNull = -400



enum PageStatus {
    case success,failed(Int)
}



class PageStatusView: UIView {
    
    var didClick : (()->())?
    
    private var statusImage : UIImageView!
    private let bgColor : UIColor  = UIColor.white
    init(status:PageStatus) {
        super.init(frame: CGRect.zero)
        self.backgroundColor = bgColor
         statusImage = UIImageView()
        statusImage.isUserInteractionEnabled = true
        switch status {
        case .success:
            break
        case .failed(let code):
            if code == Request_error{
                
            }else if code == Request_timeout {
                statusImage.image = UIImage(named:"Bitmap_icon_net")
            }else if code == DataNull {
                
            }
        }
        self.addSubview(statusImage)
        let tap  = UITapGestureRecognizer(target: self, action: #selector(PageStatusView.imageTapClick(tap:)))
        statusImage.addGestureRecognizer(tap)
    }
    @objc func imageTapClick(tap:UITapGestureRecognizer)  {
        didClick?()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        statusImage.center = self.center
        statusImage.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
}
